#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
	while(1){
    	string filename;
   		cout << "Enter the filename: ";
    	cin >> filename;
    	ifstream file(filename);
    	if (!file) {
        	cout << "Error: couldn't open the file!" << endl;
        	return 1; //若文件不能被打开，则退出程序；
    	}
    	string ch;
    	int charCount = 0;
    	int wordCount = 0;
		int sentCount = 0;
    	while (getline(file, ch)) {
        	for (int i = 0; i < ch.length(); i++) {
            	char c = ch[i];
            	charCount++;
            	if (c == ' ' || c == '\t') {
				// 空格或制表符表示单词边界；
                	wordCount++;
            	}
            	else if (c == '.' || c == '?' || c == '!') {
            	// 读取到句子；
                	sentCount++;
				}
        	}
    	}
    	// 为文件的最后字符+1；
    	wordCount++;
    	file.close();
    	cout << "Character count: " << charCount << endl;
    	cout << "Word count: " << wordCount << endl;
		cout << "Sentence count: " << sentCount << endl;
		cout << "Thank you for using it"<<endl<<endl;
	}						
    	return 0;
}